package com.ijiuchuang.jc_localization.presenter.tools;

import android.content.Context;

import com.ijiuchuang.jc_localization.bean.entity.BleDevice;
import com.ijiuchuang.jc_localization.ble.BleCallback;
import com.ijiuchuang.jc_localization.ble.BleUtil;
import com.ijiuchuang.jc_localization.contract.tools.ToolsRssiContract;
import com.ijiuchuang.jc_localization.model.tools.ToolsRssiModel;

import java.util.List;

/**
 * Created by Veev on 2016/6/18
 *
 * @link 384506557@qq.com
 */
public class ToolsRssiPresenter implements ToolsRssiContract.Presenter {

    private Context mContext;
    private ToolsRssiContract.View mView;
    private ToolsRssiContract.Model mModel;

    public ToolsRssiPresenter(Context mContext, ToolsRssiContract.View mView) {
        this.mContext = mContext;
        this.mView = mView;
        mModel = new ToolsRssiModel();

        mView.setPresenter(this);
    }

    @Override
    public void start() {
        // start here
        BleUtil.bleInit(mContext, new BleCallback.BleInitListener() {
            @Override
            public void onSuccess() {
                // 功能正常
                mView.setFabIcon(mModel.getBleEnableRes());
            }

            @Override
            public void onDisEnabled() {
                // 提示开启蓝牙
                mView.openBle();
            }

            @Override
            public void onFailure() {
                // 蓝牙功能异常，提示，并退出
            }
        });
    }

    @Override
    public void startScan() {
        mModel.startScan(new ToolsRssiContract.Model.BleDeviceChangedListener() {
            @Override
            public void onCreated(List<BleDevice> list) {
                mView.setDatas(list);
            }

            @Override
            public void onUpdated(int position, BleDevice device) {
                mView.updateDevice(position, device);
            }

            @Override
            public void onAdd(BleDevice device) {
                mView.addDevice(device);
            }
        });
    }
}